package org.kleathome.dcpu16;

public abstract class DCPU16Value
{
	public abstract char getValue();
	public abstract void setValue(char in);
	public abstract int getCycleCost();
	public abstract int getInstructionWords();
	static public DCPU16Value getValue(char value)
	{
		//System.out.println(Integer.toHexString(value));
		if (value >= 0x00 && value <= 0x07)
		{
			return new DCPU16Register(value);
		}
		else if (value >= 0x08 && value <= 0x0F)
		{
			return new DCPU16Address(value);
		}
		else if (value >= 0x10 && value <= 0x17)
		{
			return new DCPU16Address(value);
		}
		else if (value >= 0x18 && value <= 0x1A)
		{
			return new DCPU16Address(value);
		}
		else if (value >= 0x1B && value <= 0x1D)
		{
			return new DCPU16Register(value);
		}
		else if (value == 0x1E)
		{
			return new DCPU16Address(value);
		}
		else if (value == 0x1F)
		{
			return new DCPU16Literal(value);
		}
		else if (value >= 0x20 && value <= 0x3F)
		{
			return new DCPU16Literal(value);
		}
		System.err.println("Unknow value in instruction code: " + value);
		System.exit(2);
		return null;
	}
	public abstract void updateJumpAddresses();
	public abstract int getOpCode();
	public abstract char getDataCode();
}
